package com.example.coffeeseller_2.model.helper.view_helper;

import android.content.Context;
import android.content.res.Configuration;

import java.util.Locale;

/**
 * Created by WH on 2018/8/10.
 * 语言切换辅助类
 */

public class LanguageSwitchHelper {

    public static void switchLanguage(Context context, String sta) {

        if (sta.equals("en")) {
            Locale.setDefault(Locale.ENGLISH);
            Configuration config = context.getResources().getConfiguration();
            config.locale = Locale.ENGLISH;
            context.getResources().updateConfiguration(config
                    , context.getResources().getDisplayMetrics());
        } else {
            Locale.setDefault(Locale.CHINESE);
            Configuration config = context.getResources().getConfiguration();
            config.locale = Locale.CHINESE;
            context.getResources().updateConfiguration(config
                    , context.getResources().getDisplayMetrics());
        }
      /*  Intent intent = new Intent(context, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(intent);*/
    }
}
